<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->

<!-- Mirrored from minetest.gitlab.io/minetest/translations/ by HTTrack Website Copier/3.x [XR&CO'2014], Thu, 01 Oct 2020 14:46:34 GMT -->
<!-- Added by HTTrack --><meta http-equiv="content-type" content="text/html;charset=utf-8" /><!-- /Added by HTTrack -->
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  
  
  
  <link rel="shortcut icon" href="../img/favicon.ico">
  <title>Translations - Minetest API Documentation</title>
  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Lato:400,700|Roboto+Slab:400,700|Inconsolata:400,700" />

  <link rel="stylesheet" href="../css/theme.css" />
  <link rel="stylesheet" href="../css/theme_extra.css" />
  <link href="../css/code_styles.css" rel="stylesheet" />
  <link href="../css/extra.css" rel="stylesheet" />
  
  <script>
    // Current page data
    var mkdocs_page_name = "Translations";
    var mkdocs_page_input_path = "translations.md";
    var mkdocs_page_url = null;
  </script>
  
  <script src="../js/jquery-2.1.1.min.js" defer></script>
  <script src="../js/modernizr-2.8.3.min.js" defer></script> 
  
</head>

<body class="wy-body-for-nav" role="document">

  <div class="wy-grid-for-nav">

    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side stickynav">
    <div class="wy-side-scroll">
      <div class="wy-side-nav-search">
        <a href="../index.html" class="icon icon-home"> Minetest API Documentation</a>
        <div role="search">
  <form id ="rtd-search-form" class="wy-form" action="http://minetest.gitlab.io/minetest/search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" title="Type search term here" />
  </form>
</div>
      </div>

      <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../index.html">Home</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../games/index.html">Games</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../mods/index.html">Mods</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../aliases/index.html">Aliases</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../textures/index.html">Textures</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../sounds/index.html">Sounds</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../registered-definitions/index.html">Registered definitions</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../nodes/index.html">Nodes</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../map-terminology-and-coordinates/index.html">Map terminology and coordinates</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../hud/index.html">HUD</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../representations-of-simple-things/index.html">Representations of simple things</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../flag-specifier-format/index.html">Flag Specifier Format</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../items/index.html">Items</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../groups/index.html">Groups</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../tools/index.html">Tools</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../entity-damage-mechanism/index.html">Entity damage mechanism</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../metadata/index.html">Metadata</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../formspec/index.html">Formspec</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../inventory/index.html">Inventory</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../colors/index.html">Colors</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../escape-sequences/index.html">Escape sequences</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../spatial-vectors/index.html">Spatial Vectors</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../helper-functions/index.html">Helper functions</a>
                    </li>
                </ul>
                <ul class="current">
                    <li class="toctree-l1 current"><a class="reference internal current" href="index.html">Translations</a>
    <ul class="current">
    <li class="toctree-l2"><a class="reference internal" href="#translating-a-string">Translating a string</a>
    </li>
    <li class="toctree-l2"><a class="reference internal" href="#operations-on-translated-strings">Operations on translated strings</a>
    </li>
    <li class="toctree-l2"><a class="reference internal" href="#translation-file-format">Translation file format</a>
    </li>
    <li class="toctree-l2"><a class="reference internal" href="#escapes">Escapes</a>
    </li>
    <li class="toctree-l2"><a class="reference internal" href="#server-side-translations">Server side translations</a>
    </li>
    </ul>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../perlin-noise/index.html">Perlin noise</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../ores/index.html">Ores</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../decoration-types/index.html">Decoration types</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../schematics/index.html">Schematics</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../lua-voxel-manipulator/index.html">Lua Voxel Manipulator</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../mapgen-objects/index.html">Mapgen objects</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../registered-entities/index.html">Registered entities</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../l-system-trees/index.html">L-system trees</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../minetest-namespace-reference/index.html">'minetest' namespace reference</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../class-reference/index.html">Class reference</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../definition-tables/index.html">Definition tables</a>
                    </li>
                </ul>
      </div>
    </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" role="navigation" aria-label="top navigation">
        <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
        <a href="../index.html">Minetest API Documentation</a>
      </nav>

      
      <div class="wy-nav-content">
        <div class="rst-content">
          <div role="navigation" aria-label="breadcrumbs navigation">
  <ul class="wy-breadcrumbs">
    <li><a href="../index.html">Docs</a> &raquo;</li>
    
      
    
    <li>Translations</li>
    <li class="wy-breadcrumbs-aside">
      
    </li>
  </ul>
  
  <hr/>
</div>
          <div role="main">
            <div class="section">
              
                <h1 id="translations">Translations<a class="headerlink" href="#translations" title="Permanent link">&para;</a></h1>
<p>Texts can be translated client-side with the help of <code>minetest.translate</code> and
translation files.</p>
<h2 id="translating-a-string">Translating a string<a class="headerlink" href="#translating-a-string" title="Permanent link">&para;</a></h2>
<p>Two functions are provided to translate strings: <code>minetest.translate</code> and
<code>minetest.get_translator</code>.</p>
<ul>
<li>
<p><code>minetest.get_translator(textdomain)</code> is a simple wrapper around
  <code>minetest.translate</code>, and <code>minetest.get_translator(textdomain)(str, ...)</code> is
  equivalent to <code>minetest.translate(textdomain, str, ...)</code>.
  It is intended to be used in the following way, so that it avoids verbose
  repetitions of <code>minetest.translate</code>:</p>
<p>local S = minetest.get_translator(textdomain)
  S(str, ...)</p>
</li>
</ul>
<p>As an extra commodity, if <code>textdomain</code> is nil, it is assumed to be "" instead.</p>
<ul>
<li><code>minetest.translate(textdomain, str, ...)</code> translates the string <code>str</code> with
  the given <code>textdomain</code> for disambiguation. The textdomain must match the
  textdomain specified in the translation file in order to get the string
  translated. This can be used so that a string is translated differently in
  different contexts.
  It is advised to use the name of the mod as textdomain whenever possible, to
  avoid clashes with other mods.
  This function must be given a number of arguments equal to the number of
  arguments the translated string expects.
  Arguments are literal strings -- they will not be translated, so if you want
  them to be, they need to come as outputs of <code>minetest.translate</code> as well.</li>
</ul>
<p>For instance, suppose we want to translate "@1 Wool" with "@1" being replaced
  by the translation of "Red". We can do the following:</p>
<div class="codehilite"><pre><span></span><code>  <span class="n">local</span> <span class="n">S</span> <span class="o">=</span> <span class="n">minetest</span><span class="p">.</span><span class="n">get_translator</span><span class="p">()</span>
  <span class="n">S</span><span class="p">(</span><span class="s">&quot;@1 Wool&quot;</span><span class="p">,</span> <span class="n">S</span><span class="p">(</span><span class="s">&quot;Red&quot;</span><span class="p">))</span>
</code></pre></div>

<p>This will be displayed as "Red Wool" on old clients and on clients that do
  not have localization enabled. However, if we have for instance a translation
  file named <code>wool.fr.tr</code> containing the following:</p>
<div class="codehilite"><pre><span></span><code>  <span class="mi">@1</span> <span class="n">Wool</span><span class="o">=</span><span class="n">Laine</span> <span class="mi">@1</span>
  <span class="n">Red</span><span class="o">=</span><span class="n">Rouge</span>
</code></pre></div>

<p>this will be displayed as "Laine Rouge" on clients with a French locale.</p>
<h2 id="operations-on-translated-strings">Operations on translated strings<a class="headerlink" href="#operations-on-translated-strings" title="Permanent link">&para;</a></h2>
<p>The output of <code>minetest.translate</code> is a string, with escape sequences adding
additional information to that string so that it can be translated on the
different clients. In particular, you can't expect operations like string.length
to work on them like you would expect them to, or string.gsub to work in the
expected manner. However, string concatenation will still work as expected
(note that you should only use this for things like formspecs; do not translate
sentences by breaking them into parts; arguments should be used instead), and
operations such as <code>minetest.colorize</code> which are also concatenation.</p>
<h2 id="translation-file-format">Translation file format<a class="headerlink" href="#translation-file-format" title="Permanent link">&para;</a></h2>
<p>A translation file has the suffix <code>.[lang].tr</code>, where <code>[lang]</code> is the language
it corresponds to. It must be put into the <code>locale</code> subdirectory of the mod.
The file should be a text file, with the following format:</p>
<ul>
<li>Lines beginning with <code># textdomain:</code> (the space is significant) can be used
  to specify the text domain of all following translations in the file.</li>
<li>All other empty lines or lines beginning with <code>#</code> are ignored.</li>
<li>Other lines should be in the format <code>original=translated</code>. Both <code>original</code>
  and <code>translated</code> can contain escape sequences beginning with <code>@</code> to insert
  arguments, literal <code>@</code>, <code>=</code> or newline (See [Escapes] below).
  There must be no extraneous whitespace around the <code>=</code> or at the beginning or
  the end of the line.</li>
</ul>
<h2 id="escapes">Escapes<a class="headerlink" href="#escapes" title="Permanent link">&para;</a></h2>
<p>Strings that need to be translated can contain several escapes, preceded by <code>@</code>.</p>
<ul>
<li><code>@@</code> acts as a literal <code>@</code>.</li>
<li><code>@n</code>, where <code>n</code> is a digit between 1 and 9, is an argument for the translated
  string that will be inlined when translated. Due to how translations are
  implemented, the original translation string <strong>must</strong> have its arguments in
  increasing order, without gaps or repetitions, starting from 1.</li>
<li><code>@=</code> acts as a literal <code>=</code>. It is not required in strings given to
  <code>minetest.translate</code>, but is in translation files to avoid being confused
  with the <code>=</code> separating the original from the translation.</li>
<li><code>@\n</code> (where the <code>\n</code> is a literal newline) acts as a literal newline.
  As with <code>@=</code>, this escape is not required in strings given to
  <code>minetest.translate</code>, but is in translation files.</li>
<li><code>@n</code> acts as a literal newline as well.</li>
</ul>
<h2 id="server-side-translations">Server side translations<a class="headerlink" href="#server-side-translations" title="Permanent link">&para;</a></h2>
<p>On some specific cases, server translation could be useful. For example, filter
a list on labels and send results to client. A method is supplied to achieve
that:</p>
<p><code>minetest.get_translated_string(lang_code, string)</code>: Translates <code>string</code> using
translations for <code>lang_code</code> language. It gives the same result as if the string
was translated by the client.</p>
<p>The <code>lang_code</code> to use for a given player can be retrieved from
the table returned by <code>minetest.get_player_information(name)</code>.</p>
<p>IMPORTANT: This functionality should only be used for sorting, filtering or similar purposes.
You do not need to use this to get translated strings to show up on the client.</p>
              
            </div>
          </div>
          <footer>
  
    <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
      
        <a href="../perlin-noise/index.html" class="btn btn-neutral float-right" title="Perlin noise">Next <span class="icon icon-circle-arrow-right"></span></a>
      
      
        <a href="../helper-functions/index.html" class="btn btn-neutral" title="Helper functions"><span class="icon icon-circle-arrow-left"></span> Previous</a>
      
    </div>
  

  <hr/>

  <div role="contentinfo">
    <!-- Copyright etc -->
    
  </div>

  Built with <a href="https://www.mkdocs.org/">MkDocs</a> using a <a href="https://github.com/snide/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org/">Read the Docs</a>.
</footer>
      
        </div>
      </div>

    </section>

  </div>

  <div class="rst-versions" role="note" aria-label="versions">
    <span class="rst-current-version" data-toggle="rst-current-version">
      
      
        <span><a href="../helper-functions/index.html" style="color: #fcfcfc;">&laquo; Previous</a></span>
      
      
        <span style="margin-left: 15px"><a href="../perlin-noise/index.html" style="color: #fcfcfc">Next &raquo;</a></span>
      
    </span>
</div>
    <script>var base_url = '../index.html';</script>
    <script src="../js/theme.js" defer></script>
      <script src="../search/main.js" defer></script>
    <script defer>
        window.onload = function () {
            SphinxRtdTheme.Navigation.enable(true);
        };
    </script>

</body>

<!-- Mirrored from minetest.gitlab.io/minetest/translations/ by HTTrack Website Copier/3.x [XR&CO'2014], Thu, 01 Oct 2020 14:46:34 GMT -->
</html>
